package kr.pe.johnkim.carrotpoint.mobile.controller;

import kr.pe.johnkim.carrotpoint.mobile.domain.CarrotPointMerchantBank;
import kr.pe.johnkim.carrotpoint.mobile.service.CarrotPointMerchantBankService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Carrot Point 가맹점 결제 은행 관련 controller 클래스 이다.
 *
 * @author : John_Kim <cale9797@gmail.com>
 * @date : 13. 2. 6.
 */
@Controller
@RequestMapping(value = "/carrotPointMerchantBankController")
public class CarrotPointMerchantBankController {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(CarrotPointMerchantBankController.class);

    @Autowired
    private CarrotPointMerchantBankService carrotPointMerchantBankService;

    /**
     * 가맹점 거래 은행을 등록 한다.
     *
     * @param carrotPointMerchantBank
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/registerMerchantBank", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public CarrotPointMerchantBank registerMerchantBank
            (@RequestBody CarrotPointMerchantBank carrotPointMerchantBank) throws Exception {
        logger.info("registerMerchantBank");

        CarrotPointMerchantBank result = new CarrotPointMerchantBank();

        try {
            carrotPointMerchantBankService.registerMerchantBank(carrotPointMerchantBank);
            result.setResult("SUCCESS");
            logger.info("success to register merchant bank.");
        } catch (Exception e) {
            result.setResult("FAIL");
            logger.info("fail to register merchant bank.");
        }

        return result;
    }

    /**
     * 가맹점 거래 은행 목록을 가져 온다.
     *
     * @param carrotPointMerchantBank
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getMerchantBankList", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public List<CarrotPointMerchantBank> getMerchantBankList
            (@RequestBody CarrotPointMerchantBank carrotPointMerchantBank) throws Exception {
        logger.info("getMerchantBankList");

        return carrotPointMerchantBankService.getMerchantBankList(carrotPointMerchantBank);
    }

    /**
     * 가맹점 거래 은행 정보를 가져 온다.
     *
     * @param carrotPointMerchantBank
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getMerchantBankInformation", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public CarrotPointMerchantBank getMerchantBankInformation
            (@RequestBody CarrotPointMerchantBank carrotPointMerchantBank) throws Exception {
        logger.info("getMerchantBankInformation");

        return carrotPointMerchantBankService.getMerchantBankInformation(carrotPointMerchantBank);
    }

    /**
     *
     * @param carrotPointMerchantBank
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/updateMerchantBankInformation", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public CarrotPointMerchantBank updateMerchantBankInformation
            (@RequestBody CarrotPointMerchantBank carrotPointMerchantBank) throws Exception {
        logger.info("updateMerchantBankInformation");

        CarrotPointMerchantBank result = new CarrotPointMerchantBank();

        try {
            carrotPointMerchantBankService.updateMerchantBankInformation(carrotPointMerchantBank);
            result.setResult("SUCCESS");
            logger.info("success to update merchant bank information.");
        } catch (Exception e) {
            result.setResult("FAIL");
            logger.info("fail to update merchant bank information.");
        }

        return result;
    }

    /**
     * 가맹점 거래 은행을 비활성화 한다.
     * 비활성화 하면 다시 등록해야 한다.
     *
     * @param carrotPointMerchantBank
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/updateDeactivateMerchantBank", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public CarrotPointMerchantBank updateDeactivateMerchantBank
            (@RequestBody CarrotPointMerchantBank carrotPointMerchantBank) throws Exception {
        logger.info("updateDeactivateMerchantBank");

        CarrotPointMerchantBank result = new CarrotPointMerchantBank();

        try {
            carrotPointMerchantBankService.updateDeactivateMerchantBank(carrotPointMerchantBank);
            result.setResult("SUCCESS");
            logger.info("success to deactivate update merchant bank.");
        } catch (Exception e) {
            result.setResult("FAIL");
            logger.info("fail to deactivate update merchant bank.");
        }

        return result;
    }
}
